public function __construct() {
parent::__construct();
- $this->addOption( 'count', "How many times to run a benchmark", false, true );
+ $this->addOption( 'count', 'How many times to run a benchmark', false, true );
}
public function bench( array $benchs ) {
'function' => $bench['function'],
'arguments' => $bench['args'],
'count' => $count,
- 'delta' => $delta,
+ 'total' => $delta,
'average' => $delta / $count,
];
}
$res['function'],
implode( ', ', $res['arguments'] )
);
- $ret .= sprintf( " %6.2fms (%6.2fms each)\n",
- $res['delta'] * 1000,
- $res['average'] * 1000
+ $ret .= sprintf( " %6.2fms (%6.4fms each)\n",
+ $res['total'] * 1e3,
+ $res['average'] * 1e3
);
}
[ 'function' => [ $this, 'getHTTP' ] ],
[ 'function' => [ $this, 'getHTTPS' ] ],
] );
- print $this->getFormattedResults();
+ $this->output( $this->getFormattedResults() );
}
- static function doRequest( $proto ) {
+ private function doRequest( $proto ) {
Http::get( "$proto://localhost/", [], __METHOD__ );
}
// bench function 1
- function getHTTP() {
+ protected function getHTTP() {
$this->doRequest( 'http' );
}
// bench function 2
- function getHTTPS() {
+ protected function getHTTPS() {
$this->doRequest( 'https' );
}
}
}
protected static function makeRandomNumber( $base, $length ) {
- $baseChars = "0123456789abcdefghijklmnopqrstuvwxyz";
- $res = "";
+ $baseChars = '0123456789abcdefghijklmnopqrstuvwxyz';
+ $res = '';
for ( $i = 0; $i < $length; $i++ ) {
$res .= $baseChars[mt_rand( 0, $base - 1 )];
}
}
}
-$maintClass = "BenchmarkDeleteTruncate";
+$maintClass = 'BenchmarkDeleteTruncate';
require_once RUN_MAINTENANCE_IF_MAIN;
[ 'function' => [ $this, 'doElseIf' ] ],
[ 'function' => [ $this, 'doSwitch' ] ],
] );
- print $this->getFormattedResults();
+ $this->output( $this->getFormattedResults() );
}
// bench function 1
- function doElseIf() {
+ protected function doElseIf() {
$a = 'z';
if ( $a == 'a' ) {
} elseif ( $a == 'b' ) {
}
// bench function 2
- function doSwitch() {
+ protected function doSwitch() {
$a = 'z';
switch ( $a ) {
case 'b':
[ 'function' => [ $this, 'benchstrtr_indirect' ] ],
[ 'function' => [ $this, 'benchstr_replace_indirect' ] ],
] );
- print $this->getFormattedResults();
+ $this->output( $this->getFormattedResults() );
}
- function benchstrtr() {
+ protected function benchstrtr() {
strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
}
- function benchstr_replace() {
+ protected function benchstr_replace() {
str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" );
}
- function benchstrtr_indirect() {
+ protected function benchstrtr_indirect() {
bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
}
- function benchstr_replace_indirect() {
+ protected function benchstr_replace_indirect() {
bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
}
}
class BenchUtf8TitleCheck extends Benchmarker {
private $data;
+ private $isutf8;
+
public function __construct() {
parent::__construct();
];
}
$this->bench( $benchmarks );
- print $this->getFormattedResults();
+ $this->output( $this->getFormattedResults() );
}
- private $isutf8;
-
- function use_regexp( $s ) {
+ protected function use_regexp( $s ) {
$this->isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
'[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
}
- function use_regexp_non_capturing( $s ) {
+ protected function use_regexp_non_capturing( $s ) {
// Same as above with a non-capturing subgroup.
$this->isutf8 = preg_match( '/^(?:[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
'[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
}
- function use_regexp_once_only( $s ) {
+ protected function use_regexp_once_only( $s ) {
// Same as above with a once-only subgroup.
$this->isutf8 = preg_match( '/^(?>[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
'[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
}
- function use_mb_check_encoding( $s ) {
+ protected function use_mb_check_encoding( $s ) {
$this->isutf8 = mb_check_encoding( $s, 'UTF-8' );
}
}
print $this->getFormattedResults();
}
- static function is_win() {
+ protected static function is_win() {
return substr( php_uname(), 0, 7 ) == 'Windows';
}
// bench function 1
- function wfIsWindows() {
+ protected function wfIsWindows() {
return self::is_win();
}
// bench function 2
- function wfIsWindowsCached() {
+ protected function wfIsWindowsCached() {
static $isWindows = null;
if ( $isWindows == null ) {
$isWindows = self::is_win();